package com.ny.dao.impl;

import com.ny.dao.OrderDao;
import com.ny.entity.Order;
import com.ny.until.Sqlconnect;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class OrderDaoImpl implements OrderDao {
    Connection conn = Sqlconnect.getCont();

    public OrderDaoImpl() throws SQLException, ClassNotFoundException {
    }

    @Override
    public int addOrder(Order order) throws SQLException {
        String  sql = "insert into orders(student_id,product_id,number,total_price) values(?,?,?,?)";
        PreparedStatement pre = conn.prepareStatement(sql);
        pre.setInt(1,order.getStudent_id());
        pre.setInt(2,order.getProduct_id());
        pre.setInt(3,order.getNumber());
        pre.setDouble(4,order.getTotal_price());
        return pre.executeUpdate();
    }
}
